package cn.com.zsw.gblog.vo;


/**
 * 功能描述
 *
 * @Author zsw
 * @Date 2019-08-06
 * @Parameter * @param null
 * @Version 1.0.0
 * @Return
 */


import cn.com.zsw.gblog.modules.gblog.enums.ResponseCode;
import lombok.Builder;

import java.io.Serializable;
@Builder
public class R implements Serializable {
    /**
     * 定义返回码
     */
//    public static final int SUCCESS_CODE = 0;
//    private static final int FAIL_CODE = 500;
//    private static final int WARN_CODE = 206;

    public static final R SUCCESS = new R(ResponseCode.SUCCESS.getCode());

    private int code;
    private String msg;
    private Object data;

    /**
     * @description: 构造函数，用于生成自定义异常
     * @author Rorschach
     * @date 2019-06-25 8:54
     */
    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R() {
    }

    private R(int code) {
        this.code = code;
        this.msg = null;
        this.data = null;
    }

    public static R status(int status) {
        return new R(status);
    }

    public R data(Object data) {
        this.data = data;
        return this;
    }

    public R msg(String msg) {
        this.msg = msg;
        return this;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "{\"code\":" + code + ", \"msg\":" + msg + ", \"data\":" + data + "}";
    }
}
